// 这个仓库 用于维护 用户所有路由规则（初始化+动态新增的）的
import { constantRoutes, asyncRoutes } from '@/router'
export default {
  namespaced: true,
  state: {
    routes: constantRoutes
  },
  mutations: {
    // store.commit('permission/setRoutes', [{}, {}, {}])
    setRoutes(state, otherRoutes) {
      state.routes = [...constantRoutes, ...otherRoutes]
    }
  },
  actions: {
    filterRoutes(context, menus) {
      // asyncRoutes  menus
      // 过滤条件: 如果你的menus中 存在一个字符串 和 模块默认路由(第一个孩子)的name字段相同
      console.log(asyncRoutes, menus)
      const res = asyncRoutes.filter(item => menus.includes(item.children[0].name))
      // console.log(res, 999888)
      context.commit('setRoutes', res)
      return res
    }
  },
  getters: {}
}
